import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import error from '@/components/error'

Vue.use(Router)

const router =  new Router({
  routes: [
  	{
  		path: '*',
  		name: 'error',
  		component: error
  	},
    {
      	path: '/',
      	name: 'HelloWorld',
      	component: HelloWorld,
      	beforeEnter: (to, from, next) => {
      		console.log('beforeEnter')
      	  	next()
      	},
    	afterEnter: (to, from) => {
        	console.log('afterEnter')
      }
    }
  ]
})

//导航开始时
router.beforeEach((to, from, next) => {
	// to 目标路由对象
	// from 即将进入的路由对象
	//next Function必须调用
	// next() 进行下一个钩子，知道全部钩子执行完
	//next(false) 中断当前
	//next('/') or next({path:'/'})
	console.log('beforeEach')
	next();
})
//导航结束时
router.afterEach((to, from) => {
	//afterEach没有next，不能改变导航
	console.log('afterEach')
})

export default router
